package com.kye.express.business.invoice_online;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;

import com.kye.base.Logger;
import com.kye.express.R;
import com.kye.express.databinding.ItemInvoiceOnlineBinding;
import com.kye.model.bean.invoice_online.GetInvoicedListResultBean;

class InvoiceOnlineItemViewBinder extends me.drakeet.multitype.ItemViewBinder<GetInvoicedListResultBean, InvoiceOnlineItemViewBinder.ViewHolder> {

    public interface OnCheckedListener{
        public void onCheckStatusChanged();
    }

    private Context mContext;
    private OnCheckedListener mListener;

    public InvoiceOnlineItemViewBinder(Context context,OnCheckedListener listener) {
        mContext = context;
        mListener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_invoice_online, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull GetInvoicedListResultBean item) {
        holder.bindData(item);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private GetInvoicedListResultBean data;
        ItemInvoiceOnlineBinding dataBinding;

        public ViewHolder(View itemView) {
            super(itemView);
            dataBinding = DataBindingUtil.bind(itemView);
        }


        public void bindData(GetInvoicedListResultBean item) {
            data = item;
            dataBinding.setData(item);
            dataBinding.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                    data.setChecked(b);
                    if (mListener != null){
                        mListener.onCheckStatusChanged();
                    }
                }
            });
        }
    }
}
